import 'package:catguard/global/global_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:line_awesome_flutter/line_awesome_flutter.dart';

import '../../config/config.dart';
import '../../generated/assets.dart';
import '../../routers/routers.dart';
import '../../views/common_widget.dart';
import 'logic.dart';

class PetManagerPage extends StatelessWidget {
  PetManagerPage({super.key});

  final logic = Get.find<PetManagerLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg,
      resizeToAvoidBottomInset: false,
      body: Stack(
        children: [
          Column(
            children: [
              CommonWidget.commonAppBar("宠物管理"),
              Container(
                width: double.infinity,
                margin: EdgeInsets.only(top: 30.w, left: 35.w, right: 35.w),
                padding: EdgeInsets.symmetric(horizontal: 35.w, vertical: 4.w),
                decoration: BoxDecoration(
                  color: Config.colorBg2,
                  borderRadius: BorderRadius.circular(Config.roundBig.w),
                ),
                child: ListView(
                  padding: const EdgeInsets.symmetric(vertical: 0),
                  scrollDirection: Axis.vertical,
                  physics: const NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  children: List.generate(global.pets.length, (index){
                    return petItem(index,(){});
                  }),
                ),
              ),
            ],
          ),
          Positioned(
              bottom: 120.w,
              child: Container(
                width: Get.width,
                alignment: Alignment.center,
                child: CommonWidget.commonButton("添加宠物", () {
                  Get.toNamed(Routes.addPet);
                }, radius: 60.w, width: 580.w),
              )),
        ],
      ),
    );
  }

  petItem(int index, Function() onTap) {
    Map pet=global.pets[index];
    return InkWell(
      onTap: onTap,
      child: Column(
        children: [
         SizedBox(
           height: 146.w,
           child:  Row(
             children: [
               //头像
               Container(
                 width: 80.w,
                 height: 80.w,
                 decoration: BoxDecoration(
                   borderRadius: BorderRadius.circular(40.w),
                   color: Config.colorMain.withOpacity(0.2),
                 ),
                 clipBehavior: Clip.antiAlias,
                 child: Image.asset(Assets.imagesPetNormal),
               ),
               SizedBox(
                 width: 24.w,
               ),
               Column(
                 mainAxisAlignment: MainAxisAlignment.center,
                 crossAxisAlignment: CrossAxisAlignment.start,
                 children: [
                   Row(
                     children: [
                       Text(
                   pet['name'],
                         style:
                         TextStyle(color: Config.colorText1, fontSize: Config.textSizeContent.sp),
                       ),
                       Text(
                         '（${ pet['type']}）',
                         style: TextStyle(color: Config.colorText3, fontSize: Config.textSizeInfo.sp),
                       ),
                     ],
                   ),
                   SizedBox(
                     height: 6.w,
                   ),
                   Row(
                     children: [
                       Icon(
                         LineAwesomeIcons.mars_solid,
                         size: 28.w,
                         color: Colors.redAccent.withOpacity(0.8),
                       ),
                       SizedBox(
                         width: 6.w,
                       ),
                       Text(
                         "已与你相伴${pet['count']}天~",
                         style: TextStyle(color: Config.colorText3, fontSize: Config.textSizeInfo.sp),
                       ),
                     ],
                   ),
                 ],
               ),
               Expanded(
                   child: Column(
                     mainAxisAlignment: MainAxisAlignment.center,
                     crossAxisAlignment: CrossAxisAlignment.end,
                     children: [
                       Icon(
                         Icons.arrow_forward_ios_rounded,
                         color: Config.colorText3.withOpacity(0.6),
                         size: 30.w,
                       ),
                     ],
                   ))
             ],
           ),
         ),
          Visibility(
            visible: global.pets.length > 1 && index < global.pets.length - 1,
            child: CommonWidget.commonDivider(),
          ),
        ],
      ),
    );
  }
}
